package br.com.ff.usuario.entidade;
import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import br.com.ff.common.StatusEnum;
import br.com.ff.usuario.to.UsuarioTO;

@Entity
@Table(name="usuario")
public class Usuario implements Serializable {
 
	private static final long serialVersionUID = 779139412652923841L;

	@Id
	@Column(name="USR_ID")
	private Long id;
	
	@Column(name="USR_LGN")
	private String login;
	
	@Column(name="USR_PWD")
	private String password;
	 
	@Column(name="USR_DHS")
	@Temporal(TemporalType.DATE)
	private Date dataCadastro;
	
	@Column(name="USR_DHE")
	@Temporal(TemporalType.DATE)
	private Date dataExpirar;
	 
	@Column(name="USR_ST")
	private int status;

//	private Cliente cliente;
	 
//	private Veiculo veiculo;
	
	public Usuario() {}
	
	public Usuario(UsuarioTO usuarioTO) {
		this.login = usuarioTO.getLogin();
		this.dataExpirar = usuarioTO.getDataExpirar();
		this.dataCadastro = usuarioTO.getDataCadastro();
		this.password = usuarioTO.getPassword();
		this.status = usuarioTO.getStatus().getStatus();
	}
	 
	public UsuarioTO parseUsuarioTO() {
		UsuarioTO usuarioTO = new UsuarioTO();
		usuarioTO.setId(this.id);
		usuarioTO.setLogin(this.login);
		usuarioTO.setPassword(this.password);
		usuarioTO.setDataCadastro(this.dataCadastro);
		usuarioTO.setDataExpirar(this.dataExpirar);
		
		if (getStatus() == StatusEnum.ATIVO.getStatus()) {
			usuarioTO.setStatus(StatusEnum.ATIVO);
		} else {
			usuarioTO.setStatus(StatusEnum.INATIVO);
		}		
		
		return usuarioTO;
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getDataCadastro() {
		return dataCadastro;
	}

	public void setDataCadastro(Date dataCadastro) {
		this.dataCadastro = dataCadastro;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Date getDataExpirar() {
		return dataExpirar;
	}

	public void setDataExpirar(Date dataExpirar) {
		this.dataExpirar = dataExpirar;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dataCadastro == null) ? 0 : dataCadastro.hashCode());
		result = prime * result
				+ ((dataExpirar == null) ? 0 : dataExpirar.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((login == null) ? 0 : login.hashCode());
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		result = prime * result + status;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Usuario other = (Usuario) obj;
		if (dataCadastro == null) {
			if (other.dataCadastro != null)
				return false;
		} else if (!dataCadastro.equals(other.dataCadastro))
			return false;
		if (dataExpirar == null) {
			if (other.dataExpirar != null)
				return false;
		} else if (!dataExpirar.equals(other.dataExpirar))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (login == null) {
			if (other.login != null)
				return false;
		} else if (!login.equals(other.login))
			return false;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if (!password.equals(other.password))
			return false;
		if (status != other.status)
			return false;
		return true;
	}

	
	
}
 
